package readwrite;

import java.util.Formatter;

public class Writer {
    
    private Formatter file; //File instance
    
    /**
     * Creates and open file with set name
     * @param _fileName file name
     */
    public void OpenFile(String _fileName)
    {
        try
        {
        file = new Formatter(_fileName + ".txt");
        file.format("%s", "POWER SIMULATOR FILE" + "\n");
        file.format("%s%s", "Version ", "1\n");
        }
        catch(Exception exception)
        {
            System.out.println("I'm fail");
        }
    }//end of OpenFile
    
    /**
     * Add record to file
     * @param _name variable name
     * @param _value variable value
     * 
     * Variable name for Version 1:
     * HouseArea, Population, WallsHeight, HouseType, TempIn0...24, TempOut0...24, Light0...24
     * 
     */
    public void AddRecord(String _name, String _value)
    {
        file.format("%s%s", _name + " ", _value + "\n");
    }
    
    /**
     * Close file
     */
    public void CloseFile()
    {
        file.close();
    }
    
    public static void main(String[] args)
    {
        Writer w = new Writer();
        w.OpenFile("Building2");
        w.AddRecord("HouseArea", "300");
        w.AddRecord("Population", "5");
        w.AddRecord("WallsHeight", "3");
        w.AddRecord("HouseType", "4");
        w.CloseFile();
    }
    
}//end of Writer
